package com.example.calculator;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class VolumeActivity extends AppCompatActivity {
    EditText text_m,text_dm,text_cm,text_mm,text_l;
    String m,dm,cm,mm,l;
    Button bm,bdm,bcm,bmm,bl,clear22;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.add_item:
                Toast.makeText(this, "普通计算器", Toast.LENGTH_SHORT).show();
                Intent intent1=new Intent(VolumeActivity.this, HelloWorldActivity.class);
                startActivity(intent1);
                break;
            case R.id.remove_item:
                Toast.makeText(this, "科学计算器", Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(VolumeActivity.this, SecondActivity.class);
                startActivity(intent);
                break;
            case R.id.changdu:
                Toast.makeText(this, "进制转换", Toast.LENGTH_SHORT).show();
                Intent intent2=new Intent(VolumeActivity.this,ThirdActivity.class);
                startActivity(intent2);
                break;
            case R.id.volume:
                Toast.makeText(this, "体积转换", Toast.LENGTH_SHORT).show();
            case R.id.length:
                Toast.makeText(this, "进制转换", Toast.LENGTH_SHORT).show();
                Intent intent3=new Intent(VolumeActivity.this,LengthActivity.class);
                startActivity(intent3);
                break;
            case R.id.text:
                Toast.makeText(this,"帮助",Toast.LENGTH_SHORT).show();
                Intent intent4=new Intent(VolumeActivity.this, HelpActivity.class);
                startActivity(intent4);
                break;
            default:
        }
        return true;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volume);

        bm = (Button) findViewById(R.id.bm);
        bdm = (Button) findViewById(R.id.bdm);
        bcm = (Button) findViewById(R.id.bcm);
        bmm = (Button) findViewById(R.id.bmm);
        bl = (Button) findViewById(R.id.bl);
        clear22 = (Button) findViewById(R.id.clear22);
        text_m = (EditText) findViewById(R.id.m);
        text_dm = (EditText) findViewById(R.id.dm);
        text_cm = (EditText) findViewById(R.id.cm);
        text_mm = (EditText) findViewById(R.id.mm);
        text_l = (EditText) findViewById(R.id.l);

        bm.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                m = text_m.getText().toString();

                dm = String.valueOf((Double.valueOf(m)*1000));
                cm = String.valueOf((Double.valueOf(m)*1000000));
                mm=String.valueOf((Double.valueOf(m)*1000000000));;
                l=String.valueOf((Double.valueOf(m)*1000));

                text_dm.setText(dm);
                text_cm.setText(cm);
                text_mm.setText(mm);
                text_l.setText(l);
            }
        });
        bdm.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                dm = text_dm.getText().toString();

                m = String.valueOf((Double.valueOf(dm)/1000));
                cm = String.valueOf((Double.valueOf(dm)*1000));
                mm=String.valueOf((Double.valueOf(dm)*1000000));;
                l=String.valueOf((Double.valueOf(dm)));

                text_m.setText(m);
                text_cm.setText(cm);
                text_mm.setText(mm);
                text_l.setText(l);
            }
        });
        bcm.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                cm = text_cm.getText().toString();

                m = String.valueOf((Double.valueOf(cm)/1000000));
                dm = String.valueOf((Double.valueOf(cm)*1000));
                mm=String.valueOf((Double.valueOf(cm)*1000));;
                l=String.valueOf((Double.valueOf(cm)/1000));

                text_dm.setText(dm);
                text_m.setText(m);
                text_mm.setText(mm);
                text_l.setText(l);
            }
        });
        bmm.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                mm = text_mm.getText().toString();

                dm = String.valueOf((Double.valueOf(mm)/1000000));
                cm = String.valueOf((Double.valueOf(mm)/1000));
                m=String.valueOf((Double.valueOf(mm)/1000000000));;
                l=String.valueOf((Double.valueOf(mm)/1000000));

                text_dm.setText(dm);
                text_cm.setText(cm);
                text_m.setText(m);
                text_l.setText(l);
            }
        });
        bl.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                l = text_l.getText().toString();

                dm = String.valueOf((Double.valueOf(l)));
                cm = String.valueOf((Double.valueOf(l)*1000));
                mm=String.valueOf((Double.valueOf(l)*1000000));;
                m=String.valueOf((Double.valueOf(l)/1000));

                text_dm.setText(dm);
                text_cm.setText(cm);
                text_mm.setText(mm);
                text_m.setText(m);
            }
        });
        clear22.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                text_m.setText("");
                text_dm.setText("");
                text_cm.setText("");
                text_mm.setText("");
                text_l.setText("");
            }
        });

    }
}
